﻿using System;
using _5E.Infrastructure.UnitOfWork;
using _5E.NHibernateRepository;
using _5E.NHibernateRepository.Repository;
using Melee.Models.Entity;
using Melee.Models.Repository;
using NHibernate;
using NHibernate.Criterion;

namespace Melee.Repository
{
    public class AreaRepository : RepositoryBase<Area, Guid>, IAreaRepository
    {
        public AreaRepository(IUnitOfWork uow) : base(uow) { }

        public Int32[] FindMaxXAndMaxY()
        {
            ICriteria criteria = SessionFactory.CurrentSession.CreateCriteria<Area>().SetProjection(
                Projections.ProjectionList().Add(Projections.Max<Area>(a => a.X))
                    .Add(Projections.Max<Area>(a => a.Y)));
            object[] result = criteria.UniqueResult<object[]>();

            return new Int32[] { Convert.ToInt32(result[0]), Convert.ToInt32(result[1]) };
        }
    }
}
